using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

using Zune.Forms;

namespace TestForms
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Form
    {
        ListBox _listBox;
        Texture2D _smiley;
        Label _buttonLabel;
        Label _checkLabel;
        Label _listBoxLabel;

        public Game1()
        {
            // Frame rate is 30 fps by default for Zune.
            TargetElapsedTime = TimeSpan.FromSeconds(1 / 30.0);

            TabControl tc = new TabControl(this);

            TabPage tp0 = new TabPage(tc);
            tp0.Text = "TextBox";
            tp0.BackColor = Color.Pink;

            Label fName = new Label(this);
            fName.ForeColor = Color.Black;
            fName.BorderType = Enumerations.BorderType.BorderNone;
            fName.Text = "First Name:";
            fName.AutoSize = true;
            fName.Location = new Vector2(10, 10);
            tp0.AddControl(fName);

            TextBox tbFirstName = new TextBox(this);
            tbFirstName.BackColor = Color.White;
            tbFirstName.ForeColor = Color.Black;
            tbFirstName.Text = string.Empty;
            tbFirstName.Location = new Vector2(10, 41);
            tbFirstName.Size = new Vector2(252, tbFirstName.Size.Y);
            tp0.AddControl(tbFirstName);

            Label lName = new Label(this);
            lName.ForeColor = Color.Black;
            lName.BorderType = Enumerations.BorderType.BorderNone;
            lName.Text = "Last Name:";
            lName.AutoSize = true;
            lName.Location = new Vector2(10, 83);
            tp0.AddControl(lName);

            TextBox tbLastName = new TextBox(this);
            tbLastName.BackColor = Color.White;
            tbLastName.ForeColor = Color.Black;
            tbLastName.Text = string.Empty;
            tbLastName.Location = new Vector2(10, 114);
            tbLastName.Size = new Vector2(252, tbLastName.Size.Y);
            tp0.AddControl(tbLastName);

            Label lPass = new Label(this);
            lPass.ForeColor = Color.Black;
            lPass.BorderType = Enumerations.BorderType.BorderNone;
            lPass.Text = "Password:";
            lPass.AutoSize = true;
            lPass.Location = new Vector2(10, 156);
            tp0.AddControl(lPass);

            TextBox tbPass = new TextBox(this);
            tbPass.BackColor = Color.White;
            tbPass.ForeColor = Color.Black;
            tbPass.Text = string.Empty;
            tbPass.TextMode = Enumerations.TextModes.Password;
            tbPass.Location = new Vector2(10, 187);
            tbPass.Size = new Vector2(252, tbPass.Size.Y);
            tp0.AddControl(tbPass);

            Label lDescription = new Label(this);
            lDescription.ForeColor = Color.Black;
            lDescription.BorderType = Enumerations.BorderType.BorderNone;
            lDescription.Text = "Description";
            lDescription.AutoSize = true;
            lDescription.Location = new Vector2(10, 229);
            tp0.AddControl(lDescription);

            TextBox tbDescription = new TextBox(this);
            tbDescription.BackColor = Color.White;
            tbDescription.ForeColor = Color.Black;
            tbDescription.Text = "This shows the multi line textbox.  Click to show what the keyboard text box does.";
            tbDescription.TextMode = Enumerations.TextModes.Multiline;
            tbDescription.Location = new Vector2(10, 260);
            tbDescription.Size = new Vector2(252, 150);
            tp0.AddControl(tbDescription);

            TabPage tp1 = new TabPage(tc);
            tp1.Text = "Labels";
            tp1.BackColor = Color.Black;

            Label lbl1 = new Label(this);
            lbl1.Location = new Vector2(10, 10);
            lbl1.Size = new Vector2(252, lbl1.Size.Y);
            lbl1.BorderType = Enumerations.BorderType.BorderNone;
            lbl1.Text = "Borderless - Autosize";
            lbl1.AutoSize = true;
            tp1.AddControl(lbl1);

            Label lbl2 = new Label(this);
            lbl2.Location = new Vector2(10, 60);
            lbl2.Size = new Vector2(252, lbl2.Size.Y);
            lbl2.Text = "With Border - Autosize";
            lbl1.AutoSize = true;
            tp1.AddControl(lbl2);

            Label lbl3 = new Label(this);
            lbl3.Location = new Vector2(10, 110);
            lbl3.Size = new Vector2(252, lbl3.Size.Y);
            lbl3.TextAlignment = Enumerations.TextAlignmentTypes.Right;
            lbl3.Text = "Right Aligned";
            lbl3.AutoSize = false;
            tp1.AddControl(lbl3);

            Label lbl4 = new Label(this);
            lbl4.Location = new Vector2(10, 150);
            lbl4.Size = new Vector2(252, lbl4.Size.Y);
            lbl4.TextAlignment = Enumerations.TextAlignmentTypes.Center;
            lbl4.Text = "Center Aligned";
            lbl4.AutoSize = false;
            tp1.AddControl(lbl4);

            Label lbl5 = new Label(this);
            lbl5.Location = new Vector2(10, 190);
            lbl5.Size = new Vector2(252, lbl5.Size.Y);
            lbl5.Text = "This sample is testing the word wrap feature.  Word wrap breaks a string into line chunks to keep all of the text on the screen.";
            tp1.AddControl(lbl5);

            TabPage tp2 = new TabPage(tc);
            tp2.Text = "ListBox";
            tp1.BackColor = Color.CornflowerBlue;

            //ListBox
            _listBox = new ListBox(this);
            _listBox.Font = "ListBox";
            _listBox.Size = new Vector2(272, 390);
            _listBox.ItemClicked += new EventHandler(_listBox_ItemClicked);
            tp2.AddControl(_listBox);

            _listBoxLabel = new Label(this);
            _listBoxLabel.Text = "";
            _listBoxLabel.Location = new Vector2(0, 392);
            _listBoxLabel.Size = new Vector2(272, 38);
            tp2.AddControl(_listBoxLabel);

            TabPage tp3 = new TabPage(tc);
            tp3.Text = "Buttons";
            tp3.BackColor = Color.LightGreen;

            //Button
            Button _button = new Button(this);
            _button.Location = new Vector2(10, 10);
            _button.Text = "Button";
            _button.BorderType = Enumerations.BorderType.BorderNone;
            _button.ForeColor = Color.Black;
            _button.BackColor = tp3.BackColor;
            _button.BackgroundImage = "ButtonImage";
            _button.BackgroundImagePressed = "ButtonImageDown";
            _button.Clicked += new Control.OnControlTouched(_button_Clicked);
            tp3.AddControl(_button);

            Button _button2 = new Button(this);
            _button2.Location = new Vector2(10, 100);
            _button2.Text = "Button2";
            _button2.Clicked += new Control.OnControlTouched(_button_Clicked);
            tp3.AddControl(_button2);

            _buttonLabel = new Label(this);
            _buttonLabel.Text = "";
            _buttonLabel.Location = new Vector2(10, 150);
            _buttonLabel.Size = new Vector2(252, 40);
            tp3.AddControl(_buttonLabel);

            TabPage tp4 = new TabPage(tc);
            tp4.Text = "CheckBoxes";
            tp4.BackColor = Color.White;

            //Checkbox
            CheckBox _checkBox = new CheckBox(this);
            _checkBox.Location = new Vector2(10, 10);
            _checkBox.Text = "Checkbox";
            _checkBox.BackColor = tp4.BackColor;
            _checkBox.ForeColor = Color.Black;
            _checkBox.BorderColor = Color.Black;
            _checkBox.CheckedChanged += new EventHandler(_checkBox_CheckedChanged);
            tp4.AddControl(_checkBox);

            CheckBox _checkBox2 = new CheckBox(this);
            _checkBox2.Location = new Vector2(10, 60);
            _checkBox2.Checked = true;
            _checkBox2.BackColor = tp4.BackColor;
            _checkBox2.ForeColor = Color.Black;
            _checkBox2.BorderColor = Color.Black;
            _checkBox2.CheckedChanged += new EventHandler(_checkBox_CheckedChanged);
            _checkBox2.Text = "Checkbox2";
            tp4.AddControl(_checkBox2);

            _checkLabel = new Label(this);
            _checkLabel.Text = "";
            _checkLabel.BackColor = tp4.BackColor;
            _checkLabel.ForeColor = Color.Black;
            _checkLabel.Location = new Vector2(10, 100);
            _checkLabel.Size = new Vector2(252, _checkLabel.Size.Y);
            tp4.AddControl(_checkLabel);
        }

        private void _listBox_ItemClicked(object sender, EventArgs e)
        {
            _listBoxLabel.Text = "Selected: " + ((ListItem)sender).Text;
        }

        private void _checkBox_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox cb = (CheckBox)sender;
            if (cb.Checked)
            {
                _checkLabel.Text = cb.Text + " is checked";
            }
            else
            {
                _checkLabel.Text = cb.Text + " is not checked";
            }
        }

        private void _button_Clicked(object sender, GameTime gameTime, TouchLocation touch)
        {
            ShowMessageBox("Are you sure you want to click this button?", Enumerations.MessageBoxTypes.OkCancel);
            _buttonLabel.Text = "Clicked: " + ((Button)sender).Text;
        }

        private void AddTestData()
        {
            for (int i = 1; i < 50; i++)
            {
                _listBox.AddItem(new Zune.Forms.ListItem("Item " + i.ToString(), null, _smiley));
            }
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            //spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            _smiley = Content.Load<Texture2D>("Smiley");

            AddTestData();

            base.LoadContent();
        }

       
    }
}
